package com.roncoo.education.system.service.api.pc;

import com.roncoo.education.system.common.req.*;
import com.roncoo.education.system.common.resq.MsgPageRESQ;
import com.roncoo.education.system.common.resq.MsgViewRESQ;
import com.roncoo.education.system.service.api.pc.biz.PcApiMsgBiz;
import com.roncoo.education.system.service.api.pc.biz.PcApidepartmentBiz;
import com.roncoo.education.util.base.BaseController;
import com.roncoo.education.util.base.Page;
import com.roncoo.education.util.base.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.TimeUnit;

/**
 * 部门信息处理器
 *
 */
@Api(description = "部门信息处理器")
@RestController
@RequestMapping(value = "/system/pc/Department")
public class PcApiDepartmentController extends BaseController {

	public static  final  String SYNC_DEPARTENT_INFO_LOCK="SYNC_DEPARTENT_INFO_LOCK";


	@Autowired
	private RedisTemplate redisTemplate;

	@Autowired
	private PcApidepartmentBiz biz;


	@ApiOperation(value = "同步部门信息", notes = "同步部门信息")
	@RequestMapping(value = "/sync/DepartmentInfo", method = RequestMethod.POST)
	public Result syncDepartmentInfo() throws Exception{
		if (redisTemplate.hasKey(SYNC_DEPARTENT_INFO_LOCK)){
			return Result.error("信息正在同步 请勿重复提交");
		}
		//5秒后自动解锁
		redisTemplate.opsForValue().set(SYNC_DEPARTENT_INFO_LOCK,1,5L, TimeUnit.SECONDS);
		Result result=biz.save();
		//操作完成 删除key
		redisTemplate.delete(SYNC_DEPARTENT_INFO_LOCK);
		return result;
	}


}
